﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 猜拳
{
    enum Fight
    {
        剪刀,
        石头,
        布
    }
    class Program
    {

        static Random ran = new Random();
        static int winRound = 0;
        static int winRoundOp = 0;

        static int battleCount = 0;
        static Opponent op;
        static Player gamer;
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("--------欢迎来猜拳--------");
                Console.WriteLine("*************************");
                Console.WriteLine("********猜拳 开始********");
                Console.WriteLine("*************************");
                Console.WriteLine("出拳规则：1.剪刀  2.石头  3.布");
                Console.WriteLine("输入对战角色：1.刘备 2.孙权 3.曹操");
                string opponenter = Console.ReadLine();
                switch (opponenter)
                {
                    case "1":
                        op = new Opponent("刘备");
                        Console.WriteLine("哈，旗鼓相当的对手");
                        break;

                    case "2":
                        op = new Opponent("孙权");
                        break;

                    case "3":
                        op = new Opponent("曹操");
                        break;
                }

                Console.WriteLine("请输入您的姓名");
                string userName = Console.ReadLine();
                gamer = new Player(userName);

                Console.WriteLine();
                while (true)
                {
                    Battling();


                    Console.WriteLine("你是否还想继续游戏 Y/N");
                    string choose = Console.ReadLine();
                    if (choose.Equals("n", StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }



                }
                Console.WriteLine("===========================");
                Console.WriteLine($"{op.Name} vs {gamer.Name}");
                Console.WriteLine("对战次数{0}", battleCount);
                Console.WriteLine(@"姓名                 得分
{0}                  {1}
{2}                  {3}", gamer.Name, winRound, op.Name, battleCount - winRound);
                Console.WriteLine("是否想再来一把 Y/N");
                string choose2 = Console.ReadLine();
                if (choose2.Equals("n",StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
                else
                {
                    continue;
                }
            }
            Console.WriteLine("结束了，别再来了好吗");








            Console.ReadKey();
        }

        private static void Battling()
        {
            Console.WriteLine("请出拳：1.剪刀  2.石头  3.布");

            int throwPunch = int.Parse(Console.ReadLine());
            gamer.ThrowPunch = throwPunch;
            Change(gamer);
            Console.WriteLine(gamer.Rule());

            op.ThrowPunch = ran.Next(1, 4);
            Change(op);

            Console.WriteLine(op.Rule());
            JudgeRule(gamer, op);
            battleCount++;
        }

        static void Change(BattleInfo a)
        {
            if (a.ThrowPunch == 1)
            {
                a.ThrowPunchChinese = "剪刀";
            }
            else if (a.ThrowPunch == 2)
            {
                a.ThrowPunchChinese = "石头";
            }
            else if (a.ThrowPunch == 3)
            {
                a.ThrowPunchChinese = "布";
            }


        }
        static void JudgeRule(Player a, Opponent b)
        {
            //1.剪刀 2.石头 3.布
            if (a.ThrowPunch == 1)//剪刀
            {
                if (b.ThrowPunch == a.ThrowPunch)
                {
                    Console.WriteLine("和局，真衰！嘿嘿，等着瞧。");
                }
                else if (b.ThrowPunch == 2)
                {
                    Console.WriteLine($"笨蛋，{a.Name}输了");
                    winRoundOp++;
                }
                else if (b.ThrowPunch == 3)
                {
                    Console.WriteLine($"恭喜，{a.Name}胜出");
                    winRound++;
                }
            }

            if (a.ThrowPunch == 2)//石头
            {
                if (b.ThrowPunch == a.ThrowPunch)
                {
                    Console.WriteLine("和局，真衰！嘿嘿，等着瞧。");
                }
                else if (b.ThrowPunch == 3)
                {
                    Console.WriteLine($"笨蛋，{a.Name}输了");
                    winRoundOp++;
                }
                else if (b.ThrowPunch == 1)
                {
                    Console.WriteLine($"恭喜，{a.Name}胜出");
                    winRound++;
                }
            }
            if (a.ThrowPunch == 3)//布
            {
                if (b.ThrowPunch == a.ThrowPunch)
                {
                    Console.WriteLine("和局，真衰！嘿嘿，等着瞧。");
                }
                else if (b.ThrowPunch == 1)
                {
                    Console.WriteLine($"笨蛋，{a.Name}输了");
                    winRoundOp++;
                }
                else if (b.ThrowPunch == 2)
                {
                    Console.WriteLine($"恭喜，{a.Name}胜出");
                    winRound++;
                }
            }


        }
    }
}
